import { User } from 'src/modules/user/user.entity';
import {
  Column,
  CreateDateColumn,
  Entity,
  JoinColumn,
  ManyToOne,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';

@Entity()
export class Category {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ unique: true })
  category_name: string;

  @Column()
  category_alias: string;

  @Column()
  @ManyToOne(() => User, {
    onDelete: 'CASCADE', // 当用户被删除时，自动删除其创建的分类
    onUpdate: 'CASCADE', // 当用户ID更新时，自动更新关联的分类
    nullable: false, // 创建用户不能为空
  })
  @JoinColumn({ name: 'create_user_id' })
  create_user: number;

  @CreateDateColumn()
  create_time: Date;

  @UpdateDateColumn()
  update_time: Date;
}
